package com.wzm.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import org.json.JSONArray;

import com.wzm.manager.Tag;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Environment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;

public class UtilsTools {
	public static void setTagInt(Context context,String tag,int tagvalue)
	{
		SharedPreferences preferences = context.getSharedPreferences("MOVIE", Context.MODE_PRIVATE);
		Editor editor = preferences.edit();
		editor.putInt(tag, tagvalue);
		editor.commit();
	}
	
	public static int getTagInt(Context context,String tag)
	{
		SharedPreferences preferences = context.getSharedPreferences("MOVIE", Context.MODE_PRIVATE);
		int tagvalue = preferences.getInt(tag,0);
		return tagvalue;
	}
	
	public static void setTagString(Context context,String tag,String value)
	{
		SharedPreferences preferences = context.getSharedPreferences("MOVIE", Context.MODE_PRIVATE);
		Editor editor = preferences.edit();
		editor.putString(tag, value);
		editor.commit();
	}
	
	public static String getTagString(Context context,String tag)
	{
		SharedPreferences preferences = context.getSharedPreferences("MOVIE", Context.MODE_PRIVATE);
		String tagvalue = preferences.getString(tag,getDate());
		return tagvalue;
	}
	
//	public static void setTagLong(Context context,String tag,Long value)
//	{
//		SharedPreferences preferences = context.getSharedPreferences("MOVIE", Context.MODE_PRIVATE);
//		Editor editor = preferences.edit();
//		editor.putLong(tag, value);
//		editor.commit();
//	}
//	
//	public static Long getTagLong(Context context,String tag)
//	{
//		SharedPreferences preferences = context.getSharedPreferences("MOVIE", Context.MODE_PRIVATE);
//		Long tagvalue = preferences.getLong(tag,0L);
//		return tagvalue;
//	}
	
	
	public static String getDate()
	{
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		return df.format(new Date());// new Date()为获取当前系统时间
	}
	public static long getNow()
	{
		return System.currentTimeMillis();
	}
	
	public static boolean hasSdcard() {
		String status = Environment.getExternalStorageState();
		if (status.equals(Environment.MEDIA_MOUNTED)) {
	        return true;
		} else {
	        return false;
		}
	}
	
	public static int getRandomInt(int size)
	{
		int a = 0;
		if(size!=0)
		{
			Random random = new Random();
			a =Math.abs(random.nextInt())%size;	
		}		
		return a;
	}
	
	public static JSONArray ListToJson(List<String> list)
	{
		JSONArray jsonarray = new JSONArray();
		if(null!=list&&list.size()>0)
		{
			for(int i=0;i<list.size();i++)
			{
				jsonarray.put(list.get(i));
			}
		}
		return jsonarray;
	}
}
